package org.dandsoft.blackbox.snn;

import javax.imageio.ImageIO;
import java.io.File;
import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * Created by IntelliJ IDEA.
 * User: dvilyuzhanin
 * Date: 25.03.2009 19:20:08
 */
public class TraceDiagramPainter {


    public static void main(String[] args) throws Exception {
        String file = args[0];
        File traceFile = new File(file);
        EnviromentTraceReader reader = new EnviromentTraceReader(traceFile);
        int size = reader.getMax() - reader.getMin() + 1;
        BufferedImage image = new BufferedImage(size, 1024, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        Graphics2D graphics = (Graphics2D) g;

        ObjectId id = null;
        Value value = null;
        int counter = 0;
        int line = 0;
        while ((id = reader.readId()) != null) {
            Value val = reader.readValue();
            if (id.getValue() != Integer.MIN_VALUE) {
                graphics.setColor(new Color((int) (val.getValue()*1000000000)));
                graphics.drawLine(counter, line, counter, line);
                System.out.print("[" + counter + "]" + id.getValue() + ":" + val.getValue() + ",");
            } else {
                graphics.setColor(Color.white);
                graphics.drawLine(counter, line, counter, line);
            }
            counter++;
            if (counter >= size) {
                counter = 0;
                line++;
                System.out.print("\n[" + line + "]: ");
            }

        }
        ImageIO.write(image, "bmp", new File(traceFile.getAbsolutePath() + ".bmp"));
    }
}
